﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Scripting;
using Microsoft.Scripting.Ast;
using Microsoft.Linq.Expressions;

namespace DlrBasic.Parser.Ast
{
    class Dim : Statement
    {
        VariableOrCall[] expressions;

        public Dim(SourceSpan span, VariableOrCall[] expressions)
            : base(span)
        {
            this.expressions = expressions;
        }

        protected internal override Expression Generate(DlrBasicGenerator generator, StateMemberGenerator stateParameter, LambdaBuilder builder)
        {
            List<Expression> dimExpressions = new List<Expression>();
            for (int i = 0; i < expressions.Length; i++)
            {
                dimExpressions.Add(expressions[i].GenerateArrayDefinition(generator));
            }
            dimExpressions.Add(base.Generate(generator, stateParameter, builder));
            return Expression.Block(dimExpressions.ToArray());
        }
    }
}
